const fileCache = require("think-cache-file");
const { Console, File, DateFile } = require("think-logger3");
const path = require("path");
// const database = require("./database.js");
const database = require("./sqlite.js");

const isDev = think.env === "development";

/**
 * cache adapter config
 * @type {Object}
 */
exports.cache = {
  type: "file",
  common: {
    timeout: 24 * 60 * 60 * 1000 // millisecond
  },
  file: {
    handle: fileCache,
    cachePath: path.join(think.ROOT_PATH, "runtime/cache"), // absoulte path is necessarily required
    pathDepth: 1,
    gcInterval: 24 * 60 * 60 * 1000 // gc interval
  }
};

/**
 * model adapter config
 * @type {Object}
 */
// exports.model = {
//   type: 'mysql',
//   common: {
//     logConnect: isDev,
//     logSql: isDev,
//     logger: msg => think.logger.info(msg)
//   },
//   mysql: database,
//   sqlite: {

//   }
// };

exports.model = {
  type: "sqlite",
  common: {
    logConnect: isDev,
    logSql: isDev,
    logger: msg => think.logger.info(msg)
  },
  sqlite: database
};

/**
 * logger adapter config
 * @type {Object}
 */
exports.logger = {
  type: isDev ? "console" : "dateFile",
  console: {
    handle: Console
  },
  file: {
    handle: File,
    backups: 10, // max chunk number
    absolute: true,
    maxLogSize: 50 * 1024, // 50M
    filename: path.join(think.ROOT_PATH, "logs/app.log")
  },
  dateFile: {
    handle: DateFile,
    level: "ALL",
    absolute: true,
    pattern: "-yyyy-MM-dd",
    alwaysIncludePattern: true,
    filename: path.join(think.ROOT_PATH, "logs/app.log")
  }
};
